package com.cs.auth.common.utlis;

import com.cs.auth.common.entity.BaseResponse;
import com.cs.auth.common.entity.ErrorCode;
import com.cs.auth.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ParseClientResultUtils {

    public <T> T parseClientResult(BaseResponse<T> clientResult) {
        log.info("clientResult:{}", clientResult);
        int code = clientResult.getCode();
        if(code == ErrorCode.SUCCESS.getCode()){
            return clientResult.getData();
        }
        log.error("clientResult error:{}", clientResult);
        throw new BusinessException(code, clientResult.getMessage());
    }
}
